package com.braveman.im.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.braveman.im.R;
import com.braveman.im.bean.ChildBean;
import com.braveman.im.bean.GroupBean;

import java.util.List;

/**
 * 作者：qu zhao xin
 * 邮箱：qu15264880529@163.com
 * 手机号：15264880529
 * 时间：17/10/17 15:54
 */

public class AnnouncementAdapter extends BaseExpandableListAdapter {

    private List<GroupBean> list;
    private Context context;
    private TextView textView;
    private ImageView imageView;

    public AnnouncementAdapter(List<GroupBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    public AnnouncementAdapter() {
    }

    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return list.get(groupPosition).children.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return list.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return list.get(groupPosition).children.get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        GroupHolder holder;
        if (convertView == null) {
            holder = new GroupHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_group_announcement, null);
            convertView.setTag(holder);
            holder.title = (TextView) convertView.findViewById(R.id.activity_txt_announcement_name);
            holder.time = (TextView) convertView.findViewById(R.id.activity_txt_announcement_time);
            ChildBean bean = new ChildBean();

            // textView = (TextView) convertView.findViewById(R.id.group_number);
            // textView.setText();


        } else {
            holder = (GroupHolder) convertView.getTag();
        }
        holder.title.setText(list.get(groupPosition).groupName);
        holder.time.setText(list.get(groupPosition).groupTime);
        imageView = (ImageView) convertView.findViewById(R.id.item_img_arros);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("123", "2312");
            }
        });

        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        ChildHolder holder;
        if (convertView == null) {
            holder = new ChildHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_announcement, null);
            holder.title = (TextView) convertView.findViewById(R.id.item_announcement_txt);
            holder.content = (TextView) convertView.findViewById(R.id.item_announcement_content);
            //  holder.name3 = (TextView) convertView.findViewById(R.id.txt_item_category);
            // holder.iv = (ImageView) convertView.findViewById(R.id.img_item_head);
            convertView.setTag(holder);
        } else {
            holder = (ChildHolder) convertView.getTag();
        }
        ChildBean cb = list.get(groupPosition).children.get(childPosition);
        holder.title.setText(cb.title);
        holder.content.setText(cb.content);
        // holder.name3.setText(cb.name3);
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    class GroupHolder {
        TextView title;
        TextView time;
    }

    class ChildHolder {
        TextView name1, name2, name3, title, content;
        ImageView iv;
    }
}
